package com.app.web.controller.app;/**
 * @program: app-admin
 * @name AppLoginController
 * @description: app用户登录
 */

import com.app.common.core.domain.ApiResult;
import com.app.common.core.domain.model.AppLoginBody;
import com.app.common.core.domain.model.AppRegisterBody;
import com.app.framework.web.service.AppLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 *@author:
 *@program: app-admin
 *@name AppLoginController
 *@description: app用户登录/注册
 */
@Api(value = "APP用户登录注册", tags = {"APP用户登录注册接口"})
@RestController
@RequestMapping("/app")
public class AppLoginController {

    @Resource
    private AppLoginService appLoginService;

    /**
     * app用户登录
     * @param appLoginBody
     * @return {@link ApiResult}<{@link String}>
     */
    @ApiOperation("APP用户登录")
    @PostMapping("/login")
    public ApiResult<String> appLogin(@Valid @RequestBody AppLoginBody appLoginBody) {
        String token = appLoginService.appLogin(appLoginBody.getApUrPhone(), appLoginBody.getApUrPwd(), null, null);
        return ApiResult.ok(token);
    }

    /**
     * APP用户注册
     * @param appRegisterBody
     * @return {@link ApiResult}<{@link Integer}>
     */
    @ApiOperation("APP用户注册")
    @PostMapping("/register")
    public ApiResult<Integer> appRegister(@Valid @RequestBody AppRegisterBody appRegisterBody){
        return ApiResult.toR(appLoginService.appRegister(appRegisterBody));
    }
}
